<template>
  <div>
    <FormPanel ref="from" :list="formList" @formChange="changeHandle" :isSubmitBtn="false" :collapse="false" labelWidth="110" />
    <FilterTable ref="table" :columns="columns" :dataSource="tableList" :isMemoryPagination="true" :isSelectColumn="false" height="auto" :onColumnsChange="(columns) => (this.columns = columns)"> </FilterTable>
    <div
      :style="{
        position: 'absolute',
        left: 0,
        bottom: 0,
        right: 0,
        zIndex: 9,
        borderTop: '1px solid #e9e9e9',
        padding: '10px 20px',
        background: '#fff',
        textAlign: 'right',
      }"
    >
      <el-button @click="closeDrawer()">关 闭</el-button>
    </div>
  </div>
</template>
<script>
import {queryOrderLog } from '@/api/dealerSale/OrderManagement/OrderDetailQueryB/index.js';
import { dictionary } from '@/utils/dictMixin';
import moment from 'moment';
export default {
  data() {
    this.saveData = null;
    return {
      formList: this.createdFrom(),
      columns: this.createdTable(),
      tableList: [],
    };
  },
  components: {},
  props: ['rowData'],
  created() {
    this.init(this.rowData);
    this.queryLog(this.rowData);
  },
   mounted() {
    this.table = this.$refs.table.$refs.pageTable;
  },
  mixins: [dictionary],
  methods: {
    async queryLog(data) {
      const res = await queryOrderLog(data.orderId);
      this.table.EXECUTE_INSERT(res.data);
    },
    init(data) {
      console.log(data);
      for (let i in data) {
        this.formList.map((x) => {
          if (x.fieldName == i) {
            x.initialValue = data[i];
          }
        });
      }
      this.formList.find((x) => x.fieldName == 'accountId').initialValue = this.tranfer(data.accountId, data);
    },
    tranfer(field, data) {
        for (let i in data.accountTypes) {
          if (data.accountTypes[i].accountId === field) {
            return data.accountTypes[i].accountTypeName;
          }
        }
    },
    createdFrom() {
      return [
        {
          type: 'BREAK_SPACE',
          label: '订单信息',
        },

        {
          type: 'INPUT',
          label: '订单编号',
          fieldName: 'orderNo',
          placeholder: '请输入',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '订单管理号',
          fieldName: 'doNo',
          placeholder: '请输入',
          disabled: true,
        },
         {
          type: 'SELECT',
          label: '订单明细状态',
          fieldName: 'orderStatus',
          placeholder: '请选择',
          disabled: true,
          itemList: this.createDictList('2415'),
        },
        {
          type: 'SELECT',
          label: '订单类型',
          fieldName: 'orderType',
          placeholder: '请选择',
          disabled: true,
          itemList: this.createDictList('2105'),
        },
        {
          type: 'SELECT',
          label: '紧急度',
          fieldName: 'emergencyType',
          placeholder: '请选择',
          disabled: true,
          itemList: this.createDictList('2101'),
        },
        {
          type: 'INPUT',
          label: '订单经销商',
          fieldName: 'dealerName',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'SELECT',
          label: '车辆用途',
          fieldName: 'vehicleUse',
          disabled: true,
          placeholder: '请输入',
          itemList: this.createDictList('2416'),
        },
        {
          type: 'INPUT',
          label: '资金类型',
          fieldName: 'accountId',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '订单年月',
          fieldName: 'orderYearMonth',
          placeholder: '请输入',
          disabled: true,
          dateType: 'month',
        },
        {
          type: 'SELECT',
          label: '运输方式',
          fieldName: 'transportType',
          disabled: true,
          itemList: this.createDictList('2409'),
        },
        {
          type: 'INPUT',
          label: '收车地址',
          fieldName: 'address',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '送达城市',
          fieldName: 'deliveryCityName',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '联系人',
          fieldName: 'linkMan',
          disabled: true,
        },
         {
          type: 'INPUT',
          label: '联系电话',
          fieldName: 'linkPhone',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: 'VIN码',
          fieldName: 'vin',
          placeholder: '请选择',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '物料编码',
          fieldName: 'productCode',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '物料描述',
          fieldName: 'productName',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '车系',
          fieldName: 'seriesName',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '车型',
          fieldName: 'modelName',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '配置',
          fieldName: 'configName',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '选装',
          fieldName: 'optionName',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '内饰',
          fieldName: 'trimName',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '外饰',
          fieldName: 'colorName',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '市场指导价',
          fieldName: 'singleAmount',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '结算价格',
          fieldName: 'sapSettlementPrice',
          disabled: true,
        },
        {
          type: 'SELECT',
          label: '是否使用返利',
          fieldName: 'isRebate',
          disabled: true,
          itemList: this.createDictList('1004'),
        },
        {
          type: 'INPUT',
          label: '返利使用金额',
          fieldName: 'rebateAmount',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '单台实付金额',
          fieldName: 'afterDiscountRebateAmount',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '提报时间',
          fieldName: 'reportDate',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '审核人',
          fieldName: 'checkPersonName',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '审核时间',
          fieldName: 'checkDate',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '财务审核时间',
          fieldName: 'financeCheckDate',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: 'sap出库时间',
          fieldName: 'sapOutDate',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '发运下达时间',
          fieldName: 'commandDate',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '启运时间',
          fieldName: 'startDeliveryDate',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '在途位置信息',
          fieldName: 'transPosition',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '到店交付时间',
          fieldName: 'arriveDate',
          disabled: true,
        },
        {
          type: 'INPUT',
          label: '经销商收车时间',
          fieldName: 'receiveDates',
          disabled: true,
        },

        {
          type: 'BREAK_SPACE',
          label: '操作记录',
        },
      ];
    },

    createdTable() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          fixed: 'left',
          render: (props) => {
            return <span>{props.row.index + 1}</span>;
          },
        },
        {
          title: '单据执行前状态',
          dataIndex: 'beforeOrderStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2417'),
          render: (p) => {
            return <span>{this.createDictText(p.row.beforeOrderStatus, '2417')}</span>;
          },
        },
        {
          title: '单独执行后状态',
          dataIndex: 'afterOrderStatus',
          sorter: true,
          filter: true,
          filterType: 'checkbox',
          filterItems: this.createDictList('2417'),
          render: (p) => {
            return <span>{this.createDictText(p.row.afterOrderStatus, '2417')}</span>;
          },
        },
        {
          title: '操作人员',
          dataIndex: 'createdName',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
        {
          title: '操作时间',
          dataIndex: 'createdAt',
          sorter: true,
          filter: true,
          filterType: 'date-range',
        },
        {
          title: '操作类型',
          dataIndex: 'operationType',
          sorter: true,
          filter: true,
          filterType: 'input'
        },
        {
          title: '审批意见',
          dataIndex: 'auditOpinion',
          sorter: true,
          filter: true,
          filterType: 'input',
        },
      ];
    },
    changeHandle(val) {
      this.saveData = val;
    },
    async closeDrawer() {
        this.$emit('close');
    },
  },
};
</script>
